package basicservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type HospitalDepartmentEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHospitalDepartmentEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HospitalDepartmentEditLogic {
	return &HospitalDepartmentEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// HospitalDepartmentEdit 更新医院科室
func (l *HospitalDepartmentEditLogic) HospitalDepartmentEdit(in *property_service.HospitalDepartment) (*property_service.Response, error) {
	// 获取医院科室模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).HospitalDepartment
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、StockID、UpdatedAt、CreatedAt
	if _, err := do.UpdateColumns(&model.HospitalDepartment{
		ParentID:          in.ParentID,          // 父级ID
		ParentCode:        in.ParentCode,        //父级编码
		ParentLs:          in.ParentLs,          // 父级列表
		DepartmentCode:    in.DepartmentCode,    // 科室编号
		HisDepartmentCode: in.HisDepartmentCode, // HIS科室编码
		Name:              in.Name,              // 科室名称
		DepartmentType:    in.DepartmentType,    // 科室类型
		PinyinCode:        in.PinyinCode,        // 拼音简码
		Director:          in.Director,          // 科室负责人
		MaintenanceAuto:   in.MaintenanceAuto,   // 维修自动处理
		Status:            in.Status,            // 状态
		Remark:            in.Remark,            // 备注
		UpdatedAtuser:     in.UpdatedAtuser,     // 更新用户
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
